/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Bill;

import Custommer.CustommerForBill;
import Medicine.MedicineForBill;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.DateFormat;
import java.util.Calendar;
import java.util.Locale;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
import main.ketnoi;

/**
 *
 * @author ADMIN
 */
public class Bill extends javax.swing.JPanel {
    //Lay ngay he thong

    private java.util.Date today = new java.util.Date();
    Locale local = new Locale("en", "EN");
    DateFormat d = DateFormat.getDateInstance(DateFormat.MEDIUM, local);
    String date = d.format(today);
    Connection con;
    DefaultTableModel model;
    DefaultTableModel modelBillManager;

    /**
     * Creates new form Bill
     */
    public Bill() {
        ketnoi a = new ketnoi();
        con = a.connect();
        initComponents();
        model = (DefaultTableModel) jTable1.getModel();
        modelBillManager = (DefaultTableModel) jTable2.getModel();
        t5.setText(date);
        LoadBillManager();
        //code auto for bill
        t1.setEnabled(false);
        int num1 = jTable2.getRowCount();
        Calendar now = Calendar.getInstance();
        t1.setText("B" + (num1 + 1));
//            t1.setText("B" + now.get(Calendar.YEAR) + (now.get(Calendar.MONTH) + 1) + now.get(Calendar.DAY_OF_MONTH) + (num1 + 1));
    }

    public void LoadBillManager() {
        try {
            //dua du loei combobox
            jComboBox1.addItem("Choose");
            PreparedStatement st = con.prepareStatement("Select * from information_schema.columns where table_name = 'Billstotal'");
            ResultSet rs1 = st.executeQuery();
            while (rs1.next()) {
                //lay du lieu cot thu 4: name,diem,lop
                String str1 = rs1.getString(4);
                jComboBox1.addItem(str1);

            }
            //load
            String str = "Select * from Billstotal";
            PreparedStatement prst = con.prepareStatement(str);
            ResultSet rs = prst.executeQuery();
            while (rs.next()) {
                Vector b = new Vector();
                b.add(rs.getString(1));
                b.add(rs.getString(2));
                b.add(rs.getString(3));
                b.add(rs.getString(4));
                b.add(rs.getString(5));
                modelBillManager.addRow(b);
            }
        } catch (SQLException ex) {
            Logger.getLogger(Bill.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public void reset() {
        id.setText("");
        t3.setText("");
        t4.setText("");
        t5.setText(date);
        t6.setText("");
        t7.setText("");
        buttonGroup1.clearSelection();
        buttonGroup2.clearSelection();
        jTextField1.setText("");
        jLabetotal.setText("");
        //code auto for bill
        t1.setEnabled(false);
        int num1 = jTable2.getRowCount();
        Calendar now = Calendar.getInstance();
        t1.setText("B" + (num1 + 1));
//            t1.setText("B" + now.get(Calendar.YEAR) + (now.get(Calendar.MONTH) + 1) + now.get(Calendar.DAY_OF_MONTH) + (num1 + 1));
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroup1 = new javax.swing.ButtonGroup();
        buttonGroup2 = new javax.swing.ButtonGroup();
        jPanel1 = new javax.swing.JPanel();
        edit = new javax.swing.JButton();
        jLabel9 = new javax.swing.JLabel();
        del = new javax.swing.JButton();
        jLabel8 = new javax.swing.JLabel();
        add = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jLabel7 = new javax.swing.JLabel();
        t7 = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        t6 = new javax.swing.JTextField();
        jRadioButton2 = new javax.swing.JRadioButton();
        jRadioButton1 = new javax.swing.JRadioButton();
        jLabel11 = new javax.swing.JLabel();
        jTextField1 = new javax.swing.JTextField();
        check = new javax.swing.JButton();
        jRadioButton3 = new javax.swing.JRadioButton();
        jRadioButton4 = new javax.swing.JRadioButton();
        jLabetotal = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        jCheckBox1 = new javax.swing.JCheckBox();
        t1 = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        t3 = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        t5 = new javax.swing.JTextField();
        t4 = new javax.swing.JTextField();
        jLabel12 = new javax.swing.JLabel();
        id = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        jPanel2 = new javax.swing.JPanel();
        sort = new javax.swing.JButton();
        jComboBox1 = new javax.swing.JComboBox();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTable2 = new javax.swing.JTable();
        jTextField2 = new javax.swing.JTextField();
        search = new javax.swing.JButton();

        setBackground(new java.awt.Color(231, 231, 231));
        setPreferredSize(new java.awt.Dimension(777, 702));

        jPanel1.setBackground(new java.awt.Color(255, 255, 255));
        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Bill", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.TOP));

        edit.setText("Update");
        edit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                editActionPerformed(evt);
            }
        });

        del.setText("Delete");
        del.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                delActionPerformed(evt);
            }
        });

        jLabel8.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel8.setText("BillsTotal:");

        add.setText("Add");
        add.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                addActionPerformed(evt);
            }
        });

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "ID", "BillCode", "BillTypeCode", "CustomerCode", "MedicineCode", "Date", "Amount", "PricePerUnit", "Total", "Pay"
            }
        ));
        jTable1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jTable1MouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(jTable1);

        jLabel7.setText("PricePerUnit");

        t7.setEditable(false);
        t7.addAncestorListener(new javax.swing.event.AncestorListener() {
            public void ancestorMoved(javax.swing.event.AncestorEvent evt) {
            }
            public void ancestorAdded(javax.swing.event.AncestorEvent evt) {
                t7AncestorAdded(evt);
            }
            public void ancestorRemoved(javax.swing.event.AncestorEvent evt) {
            }
        });

        jLabel6.setText("Amount");

        buttonGroup1.add(jRadioButton2);
        jRadioButton2.setSelected(true);
        jRadioButton2.setText("Export");

        buttonGroup1.add(jRadioButton1);
        jRadioButton1.setText("Import");

        jLabel11.setText("Con lai:");

        jTextField1.setEditable(false);

        check.setText("Check");
        check.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                checkActionPerformed(evt);
            }
        });

        buttonGroup2.add(jRadioButton3);
        jRadioButton3.setText("Normal");
        jRadioButton3.setEnabled(false);

        buttonGroup2.add(jRadioButton4);
        jRadioButton4.setText("Discount");
        jRadioButton4.setEnabled(false);

        jLabel10.setText("Total:");

        jCheckBox1.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jCheckBox1.setText("Pay");
        jCheckBox1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCheckBox1ActionPerformed(evt);
            }
        });

        jLabel1.setText("BillCode");

        jLabel5.setText("Date");

        t3.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                t3KeyPressed(evt);
            }
        });

        jLabel4.setText("MedicineCode");

        jLabel3.setText("CustomerCode");

        jLabel2.setText("BillTypeCode");

        t5.setEditable(false);

        t4.addInputMethodListener(new java.awt.event.InputMethodListener() {
            public void caretPositionChanged(java.awt.event.InputMethodEvent evt) {
            }
            public void inputMethodTextChanged(java.awt.event.InputMethodEvent evt) {
                t4InputMethodTextChanged(evt);
            }
        });
        t4.addAncestorListener(new javax.swing.event.AncestorListener() {
            public void ancestorMoved(javax.swing.event.AncestorEvent evt) {
            }
            public void ancestorAdded(javax.swing.event.AncestorEvent evt) {
                t4AncestorAdded(evt);
            }
            public void ancestorRemoved(javax.swing.event.AncestorEvent evt) {
            }
        });
        t4.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                t4KeyPressed(evt);
            }
            public void keyTyped(java.awt.event.KeyEvent evt) {
                t4KeyTyped(evt);
            }
        });

        jLabel12.setText("ID:");

        jButton1.setText("New");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jButton2.setText("...");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jButton3.setText("...");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(45, 45, 45)
                        .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 114, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(del, javax.swing.GroupLayout.PREFERRED_SIZE, 107, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 33, Short.MAX_VALUE)
                        .addComponent(edit, javax.swing.GroupLayout.PREFERRED_SIZE, 105, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(57, 57, 57)
                        .addComponent(jLabel8, javax.swing.GroupLayout.PREFERRED_SIZE, 66, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(34, 34, 34)
                        .addComponent(jLabel9, javax.swing.GroupLayout.PREFERRED_SIZE, 115, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                        .addGroup(jPanel1Layout.createSequentialGroup()
                            .addContainerGap()
                            .addComponent(jLabel12)
                            .addGap(4, 4, 4)
                            .addComponent(id, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGap(18, 18, 18)
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addGroup(jPanel1Layout.createSequentialGroup()
                                    .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addComponent(t4, javax.swing.GroupLayout.PREFERRED_SIZE, 133, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGroup(jPanel1Layout.createSequentialGroup()
                                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                        .addComponent(jLabel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addComponent(jLabel1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addComponent(jLabel2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 89, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(t1, javax.swing.GroupLayout.PREFERRED_SIZE, 133, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGroup(jPanel1Layout.createSequentialGroup()
                                            .addComponent(jRadioButton1)
                                            .addGap(10, 10, 10)
                                            .addComponent(jRadioButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 65, javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                            .addGroup(jPanel1Layout.createSequentialGroup()
                                                .addComponent(jRadioButton3)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                                .addComponent(jRadioButton4))
                                            .addComponent(t3, javax.swing.GroupLayout.PREFERRED_SIZE, 133, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE)))
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(jPanel1Layout.createSequentialGroup()
                                    .addComponent(check, javax.swing.GroupLayout.PREFERRED_SIZE, 94, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addGap(18, 18, 18)
                                    .addComponent(add, javax.swing.GroupLayout.PREFERRED_SIZE, 105, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGroup(jPanel1Layout.createSequentialGroup()
                                    .addComponent(jLabel10, javax.swing.GroupLayout.PREFERRED_SIZE, 58, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addGap(18, 18, 18)
                                    .addComponent(jLabetotal, javax.swing.GroupLayout.PREFERRED_SIZE, 117, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addGap(43, 43, 43)
                                    .addComponent(jCheckBox1, javax.swing.GroupLayout.PREFERRED_SIZE, 76, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGroup(jPanel1Layout.createSequentialGroup()
                                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addGroup(jPanel1Layout.createSequentialGroup()
                                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addComponent(jLabel6))
                                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                                        .addGroup(jPanel1Layout.createSequentialGroup()
                                            .addComponent(jLabel7, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                            .addGap(32, 32, 32)))
                                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(t7, javax.swing.GroupLayout.PREFERRED_SIZE, 117, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGroup(jPanel1Layout.createSequentialGroup()
                                            .addComponent(t6, javax.swing.GroupLayout.PREFERRED_SIZE, 117, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                            .addComponent(jLabel11)
                                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                            .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 89, javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addComponent(t5, javax.swing.GroupLayout.PREFERRED_SIZE, 256, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                        .addGroup(jPanel1Layout.createSequentialGroup()
                            .addGap(18, 18, 18)
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 672, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap(13, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                    .addComponent(jLabel12, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 23, Short.MAX_VALUE)
                                    .addComponent(id, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                                .addGap(41, 41, 41))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addGroup(jPanel1Layout.createSequentialGroup()
                                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addGroup(jPanel1Layout.createSequentialGroup()
                                                .addGap(31, 31, 31)
                                                .addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addGroup(jPanel1Layout.createSequentialGroup()
                                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(t5, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addGroup(jPanel1Layout.createSequentialGroup()
                                                .addGap(30, 30, 30)
                                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                                    .addComponent(t6, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                    .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                    .addComponent(jLabel11, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE))))
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(t7, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabetotal, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jCheckBox1)
                                    .addComponent(jLabel10, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE))))
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(check)
                            .addComponent(add)))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(t3, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jButton2))
                                .addGap(41, 41, 41))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(t1, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addGroup(jPanel1Layout.createSequentialGroup()
                                        .addGap(30, 30, 30)
                                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                            .addComponent(jRadioButton1)
                                            .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addComponent(jRadioButton2))))
                                .addGap(29, 29, 29)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(jRadioButton3)
                                    .addComponent(jRadioButton4))))
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(t4, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jButton3))))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 169, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel8, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jButton1)
                        .addComponent(del)
                        .addComponent(edit))
                    .addComponent(jLabel9, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)))
        );

        jPanel2.setBackground(new java.awt.Color(255, 255, 255));
        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Manager", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.TOP));

        sort.setText("Sort");
        sort.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                sortActionPerformed(evt);
            }
        });

        jTable2.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "BillCode", "BillTypeCode", "CustomerCode", "Date", "Total"
            }
        ));
        jTable2.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jTable2MouseClicked(evt);
            }
        });
        jScrollPane2.setViewportView(jTable2);

        search.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Icon/search2.png"))); // NOI18N
        search.setText("Search");
        search.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                searchActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(72, 72, 72)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 550, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(sort, javax.swing.GroupLayout.PREFERRED_SIZE, 65, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, 128, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, 125, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(search, javax.swing.GroupLayout.PREFERRED_SIZE, 99, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(131, 131, 131))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(search)
                    .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(sort))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 136, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap(88, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(96, Short.MAX_VALUE))
        );

        jPanel2.getAccessibleContext().setAccessibleName("Management");
    }// </editor-fold>//GEN-END:initComponents

    private void editActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_editActionPerformed
        try {
            // TODO add your handling code here:
            //Update sql
            String s2 = "";
            if (jRadioButton1.isSelected() == true) {
                s2 = "I";
            } else {
                s2 = "E";
            }
            String d = "";
            if (jCheckBox1.isSelected() == true) {
                d = "1";
            } else {
                d = "0";
            }
            PreparedStatement pre = con.prepareStatement("update Bills set MedicineCode=?,Amount=?, pay=? where id = ?");
            pre.setString(1, t4.getText());
            pre.setString(2, t6.getText());
            pre.setString(3, d);
            pre.setString(4, id.getText());
            pre.executeUpdate();

            //Update java
            int num = jTable1.getSelectedRow();
            model.removeRow(num);

            //            int a = Integer.parseInt(t6.getText());
            //            double b = Double.parseDouble(t7.getText());

            Vector v = new Vector();
            v.add(id.getText());
            v.add(t1.getText());
            v.add(s2);
            v.add(t3.getText());
            v.add(t4.getText());
            v.add(t5.getText());
            v.add(t6.getText());
            v.add(t7.getText());
            v.add(jLabetotal.getText());
            v.add(d);
            model.addRow(v);
            PreparedStatement prst3 = con.prepareStatement("select Billstotal from Billstotal where BillCode=?");
            prst3.setString(1, t1.getText());
            ResultSet rs3 = prst3.executeQuery();
            while (rs3.next()) {
                jLabel9.setText(rs3.getString(1));
            }
            this.reset();
            int num1 = jTable2.getRowCount();
            for (int i = num1 - 1; i >= 0; i--) {
                modelBillManager.removeRow(i);
            }
            this.LoadBillManager();

        } catch (SQLException ex) {
            Logger.getLogger(Bill.class.getName()).log(Level.SEVERE, null, ex);
            JOptionPane.showMessageDialog(this, "Thong tin thay doi chua chinh xac!", "ERROR", JOptionPane.ERROR_MESSAGE);
        }
    }//GEN-LAST:event_editActionPerformed

    private void delActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_delActionPerformed
        int n = JOptionPane.showConfirmDialog(this, "     Are you sure? ", "---DELETE---", JOptionPane.YES_NO_OPTION, 2);
        if (n == 0) {
            try {
                // TODO add your handling code here:
                //Delete CSDL
                PreparedStatement pre = con.prepareStatement("Delete from Bills where id=?");
                pre.setString(1, id.getText());
                pre.executeUpdate();
                //Delete Java
                model.removeRow(jTable1.getSelectedRow());
                this.reset();
                int num = jTable2.getRowCount();
                for (int i = num - 1; i >= 0; i--) {
                    modelBillManager.removeRow(i);
                }
                this.LoadBillManager();
            } catch (SQLException ex) {
                Logger.getLogger(Bill.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }//GEN-LAST:event_delActionPerformed

    private void addActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addActionPerformed
        try {
            // TODO add your handling code here:

            //            t1.setEnabled(false);
            //            t3.setEnabled(false);
            //            jRadioButton1.setEnabled(false);
            //            jRadioButton2.setEnabled(false);
            //            jRadioButton3.setEnabled(false);
            //            jRadioButton4.setEnabled(false);
            //            reset.setEnabled(true);

            //Lua chon Import va export
            String s2 = "";
            if (jRadioButton1.isSelected() == true) {
                s2 = "I";
            } else {
                s2 = "E";
            }
            String d = "";
            if (jCheckBox1.isSelected() == true) {
                d = "1";
            } else {
                d = "0";
            }

            //Them vao co so du lieu
            if (t1.getText().length() == 0) {
                JOptionPane.showMessageDialog(this, "chua nhap Billcode", "ERROR", JOptionPane.ERROR_MESSAGE);
                t1.requestFocus();
            } else {
                if (t6.getText().length() == 0) {
                    JOptionPane.showMessageDialog(this, "chua nhap so luong", "ERROR", JOptionPane.ERROR_MESSAGE);
                    t6.requestFocus();
                } else {
                    PreparedStatement prst = con.prepareStatement("insert into Bills values (?,?,?,?,?,?,null,null,null)");
                    prst.setString(1, t1.getText());
                    prst.setString(2, s2);
                    prst.setString(3, t3.getText());
                    prst.setString(4, t4.getText());
                    prst.setString(5, t5.getText());
                    prst.setString(6, t6.getText());
                    prst.executeUpdate();
                    //            //Tinh toan cot total
                    //            PreparedStatement prst1 = con.prepareStatement("update Bills set Total=Amount*PricePerUnit");
                    //            prst1.executeUpdate();
                    //
                    //In ra bang trong java

                    //            int a1 = Integer.parseInt(t6.getText());
                    //            double c1 = Double.parseDouble(t7.getText());
                    PreparedStatement prst1 = con.prepareStatement("select max(id) from bills");
                    ResultSet rs1 = prst1.executeQuery();
                    while (rs1.next()) {
                        id.setText(rs1.getString(1));
                    }

                    //Normal or Discount
                    PreparedStatement prst3 = con.prepareStatement("select CustomerRelationshipCode from customers where CustomerCode=?");
                    prst3.setString(1, t3.getText());
                    ResultSet rs3 = prst3.executeQuery();
                    String c = null;
                    while (rs3.next()) {
                        c = rs3.getString(1);
                    }
                    System.out.println(c);
                    if (c.equals("N")) {
                        jRadioButton3.setSelected(true);
                    } else {
                        jRadioButton4.setSelected(true);
                    }

                    PreparedStatement pre1 = con.prepareStatement("select Priceperunit from bills where MedicineCode=?");
                    pre1.setString(1, t4.getText());
                    ResultSet re2 = pre1.executeQuery();
                    while (re2.next()) {
                        t7.setText(re2.getString(1));
                    }

                    //So thuoc con lai
                    PreparedStatement prst2 = con.prepareStatement("select MedicineAmount from Medicines where MedicineCode=?");
                    prst2.setString(1, t4.getText());
                    ResultSet rs2 = prst2.executeQuery();
                    String a = null;
                    while (rs2.next()) {
                        jTextField1.setText(rs2.getString(1));
                        a = rs2.getString(1);
                    }
                    //                if (Integer.parseInt(t6.getText()) > Integer.parseInt(a)) {
                    //                    t6.setText(a);
                    //                    t6.requestFocus();
                    //                    JOptionPane.showMessageDialog(this, "Nhin lai di");
                    //                } else {
                    //                    JOptionPane.showMessageDialog(this, "ok roi day");
                    //                }

                    //Total
                    //                int amount = Integer.parseInt(t6.getText());
                    //                double price = Double.parseDouble(t7.getText());
                    //                System.out.println(amount * price);
                    //                double t2 = (amount * price);
                    //                String t = Double.toString(t2);
                    //                jLabetotal.setText(t);
                    PreparedStatement prst4 = con.prepareStatement("select total from bills where id=?");
                    prst4.setString(1, id.getText());
                    ResultSet re4 = prst4.executeQuery();
                    while (re4.next()) {
                        jLabetotal.setText(re4.getString(1));
                    }
                    JOptionPane.showMessageDialog(this, "Nhap thanh cong!");
                    //load lai
                    t1.setEnabled(false);
                    t3.setEnabled(false);
                    PreparedStatement prst5 = con.prepareStatement("select Billstotal from Billstotal where BillCode=?");
                    prst5.setString(1, t1.getText());
                    ResultSet rs5 = prst5.executeQuery();
                    while (rs5.next()) {
                        jLabel9.setText(rs5.getString(1));
                    }
                    int num = jTable2.getRowCount();
                    for (int i = num - 1; i >= 0; i--) {
                        modelBillManager.removeRow(i);
                    }
                    this.LoadBillManager();
                    Vector v = new Vector();
                    v.add(id.getText());
                    v.add(t1.getText());
                    v.add(s2);
                    v.add(t3.getText());
                    v.add(t4.getText());
                    v.add(t5.getText());
                    v.add(t6.getText());
                    v.add(t7.getText());
                    v.add(jLabetotal.getText());
                    v.add(d);
                    model.addRow(v);
                    id.setText("");
                    t4.setText("");
                    t5.setText(date);
                    t6.setText("");
                    t7.setText("");
                    jTextField1.setText("");
                    jLabetotal.setText("");
                    t4.requestFocus();
                }
            }
        } catch (SQLException ex) {
            Logger.getLogger(Bill.class.getName()).log(Level.SEVERE, null, ex);
            JOptionPane.showMessageDialog(this, "Chua nhap du thong tin!\nThong tin nhap chua chinh xac!", "ERROR", JOptionPane.ERROR_MESSAGE);
        }
    }//GEN-LAST:event_addActionPerformed

    private void jTable1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTable1MouseClicked
        try {
            // TODO add your handling code here:
            add.setEnabled(false);
            int r = jTable1.getSelectedRow();
            if (r < 0) {
                return;
            }
            id.setText(jTable1.getValueAt(r, 0).toString());
            t1.setText(jTable1.getValueAt(r, 1).toString());
            t3.setText(jTable1.getValueAt(r, 3).toString());
            t4.setText(jTable1.getValueAt(r, 4).toString());
            t5.setText(jTable1.getValueAt(r, 5).toString());
            t6.setText(jTable1.getValueAt(r, 6).toString());
            t7.setText(jTable1.getValueAt(r, 7).toString());
            PreparedStatement prst3 = con.prepareStatement("select CustomerRelationshipCode from customers where CustomerCode=?");
            prst3.setString(1, t3.getText());
            ResultSet rs3 = prst3.executeQuery();
            String c = null;
            while (rs3.next()) {
                c = rs3.getString(1);
            }

            if (c.equals("N")) {
                jRadioButton3.setSelected(true);
            } else {
                jRadioButton4.setSelected(true);
            }
            PreparedStatement prst = con.prepareStatement("select billtypecode from bills where id=?");
            prst.setString(1, id.getText());
            ResultSet rs = prst.executeQuery();
            String a = null;
            while (rs.next()) {
                a = rs.getString(1);
            }

            if (a.equals("I")) {
                jRadioButton1.setSelected(true);
            } else {
                jRadioButton2.setSelected(true);
            }
            PreparedStatement prst1 = con.prepareStatement("select pay from bills where id=?");
            prst1.setString(1, id.getText());
            ResultSet rs1 = prst1.executeQuery();
            String s = null;
            while (rs1.next()) {
                s = rs1.getString(1);
            }
            System.out.println(a);
            if (s.equals("1")) {
                jCheckBox1.setSelected(true);
            } else {
                jCheckBox1.setSelected(false);
            }
            jLabetotal.setText(jTable1.getValueAt(r, 8).toString());
        } catch (SQLException ex) {
            Logger.getLogger(NewJFrame.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_jTable1MouseClicked

    private void t7AncestorAdded(javax.swing.event.AncestorEvent evt) {//GEN-FIRST:event_t7AncestorAdded
    }//GEN-LAST:event_t7AncestorAdded

    private void checkActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_checkActionPerformed
        try {
            // TODO add your handling code here:

            PreparedStatement prst1 = con.prepareStatement("select max(id)+1 from bills");
            ResultSet rs1 = prst1.executeQuery();
            while (rs1.next()) {
                id.setText(rs1.getString(1));
            }
            //Normal or Discount
            if (t3.getText().length() == 0) {
                JOptionPane.showMessageDialog(this, "Chua nhap CustomerCode!", "ERROR", JOptionPane.ERROR_MESSAGE);
                t3.requestFocus();
            } else {
                PreparedStatement prst3 = con.prepareStatement("select CustomerRelationshipCode from Customers where CustomerCode=?");
                prst3.setString(1, t3.getText());
                ResultSet rs3 = prst3.executeQuery();
                String b = null;
                while (rs3.next()) {
                    b = rs3.getString(1);
                }

                if (b.equals("N")) {
                    jRadioButton3.setSelected(true);
                } else {
                    jRadioButton4.setSelected(true);
                }

                //PricePerUnit
                if (t4.getText().length() == 0) {
                    JOptionPane.showMessageDialog(this, "Chua nhap MedicineCode!", "ERROR", JOptionPane.ERROR_MESSAGE);
                    t4.requestFocus();
                } else {
                    if (jRadioButton3.isSelected()) {
                        PreparedStatement pre = con.prepareStatement("select Price*1.2 from Medicines where MedicineCode=?");
                        pre.setString(1, t4.getText());
                        ResultSet re = pre.executeQuery();
                        while (re.next()) {
                            t7.setText(re.getString(1));
                        }
                    } else {
                        PreparedStatement pre = con.prepareStatement("select Price*1.1 from Medicines where MedicineCode=?");
                        pre.setString(1, t4.getText());
                        ResultSet re = pre.executeQuery();
                        while (re.next()) {
                            t7.setText(re.getString(1));
                        }
                    }

                    //So thuoc con lai
                    PreparedStatement prst2 = con.prepareStatement("select MedicineAmount from Medicines where MedicineCode=?");
                    prst2.setString(1, t4.getText());
                    ResultSet rs2 = prst2.executeQuery();
                    String a = null;
                    while (rs2.next()) {
                        jTextField1.setText(rs2.getString(1));
                        a = rs2.getString(1);
                    }
                }
            }
            //                if (Integer.parseInt(t6.getText()) > Integer.parseInt(a)) {
            //                    t6.setText(a);
            //                    t6.requestFocus();
            //                    JOptionPane.showMessageDialog(this, "Nhin lai di");
            //                } else {
            //                    JOptionPane.showMessageDialog(this, "ok roi day");
            //                }

            //Total
            int amount = Integer.parseInt(t6.getText());
            double price = Double.parseDouble(t7.getText());
            System.out.println(amount * price);
            double t2 = (amount * price);
            String t = Double.toString(t2);
            jLabetotal.setText(t);

        } catch (SQLException ex) {
            Logger.getLogger(Bill.class.getName()).log(Level.SEVERE, null, ex);
            JOptionPane.showMessageDialog(this, "Thong tin nhap chua chinh xac!", "ERROR", JOptionPane.ERROR_MESSAGE);
        }
    }//GEN-LAST:event_checkActionPerformed

    private void jCheckBox1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBox1ActionPerformed
        // TODO add your handling code here:
        //Update CSD
    }//GEN-LAST:event_jCheckBox1ActionPerformed

    private void t4InputMethodTextChanged(java.awt.event.InputMethodEvent evt) {//GEN-FIRST:event_t4InputMethodTextChanged
        try {
            //             TODO add your handling code here:
            PreparedStatement pre = con.prepareStatement("select Price*1.2 from Medicines where MedicineCode=?");
            pre.setString(1, t4.getText());
            ResultSet re = pre.executeQuery();
            while (re.next()) {
                t7.setText(re.getString(1));
            }
        } catch (SQLException ex) {
            Logger.getLogger(Bill.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_t4InputMethodTextChanged

    private void t4AncestorAdded(javax.swing.event.AncestorEvent evt) {//GEN-FIRST:event_t4AncestorAdded
        // TODO add your handling code here:
    }//GEN-LAST:event_t4AncestorAdded

    private void t4KeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_t4KeyPressed
        // TODO add your handling code here:
    }//GEN-LAST:event_t4KeyPressed

    private void t4KeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_t4KeyTyped
        // TODO add your handling code here:
    }//GEN-LAST:event_t4KeyTyped

    private void sortActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_sortActionPerformed
        // TODO add your handling code here:
        //xoa bang
        if (jComboBox1.getSelectedIndex() == 0) {
            JOptionPane.showMessageDialog(this, "Please select sort condition!");
        } else {
            int num = jTable2.getRowCount();
            for (int i = num - 1; i >= 0; i--) {
                modelBillManager.removeRow(i);
            }
            //sapxep
            String str = jComboBox1.getSelectedItem().toString();
            try {
                PreparedStatement pst = con.prepareStatement("Select * from Billstotal order by " + str);

                ResultSet rs1 = pst.executeQuery();
                Vector e = null;
                while (rs1.next()) {
                    e = new Vector();
                    e.add(rs1.getString(1));
                    e.add(rs1.getString(2));
                    e.add(rs1.getString(3));
                    e.add(rs1.getString(4));
                    e.add(rs1.getString(5));
                    modelBillManager.addRow(e);
                }
            } catch (SQLException ex) {
                Logger.getLogger(Bill.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }//GEN-LAST:event_sortActionPerformed

    private void searchActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_searchActionPerformed
        // TODO add your handling code here:
        //Xoa bang
        if (jComboBox1.getSelectedIndex() == 0) {
            JOptionPane.showMessageDialog(this, "Please select search condition!");
        } else {
            int num = jTable2.getRowCount();
            for (int i = num - 1; i >= 0; i--) {
                modelBillManager.removeRow(i);
            }
            //search
            String str1 = jComboBox1.getSelectedItem().toString();

            try {
                String str = jTextField2.getText();
                PreparedStatement pst = con.prepareStatement("Select * from Billstotal where " + str1 + " = ?");
                pst.setString(1, str);
                ResultSet rs1 = pst.executeQuery();
                Vector e = null;
                while (rs1.next()) {
                    e = new Vector();
                    e.add(rs1.getString(1));
                    e.add(rs1.getString(2));
                    e.add(rs1.getString(3));
                    e.add(rs1.getString(4));
                    e.add(rs1.getString(5));
                    modelBillManager.addRow(e);
                }

            } catch (SQLException ex) {
                Logger.getLogger(Bill.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }//GEN-LAST:event_searchActionPerformed

    private void jTable2MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTable2MouseClicked
        try {
            // TODO add your handling code here:
            int r = jTable2.getSelectedRow();
            if (r < 0) {
                return;
            }
            int num = jTable1.getRowCount();
            for (int i = num - 1; i >= 0; i--) {
                model.removeRow(i);
            }

            String str = jTable2.getValueAt(r, 0).toString();
            String str1 = jTable2.getValueAt(r, 1).toString();
            String str3 = jTable2.getValueAt(r, 2).toString();
            String str2 = jTable2.getValueAt(r, 3).toString();
            System.out.println(str1);
            PreparedStatement prst = con.prepareStatement("select * from bills where billcode =? and billtypecode = ? and date =?");
            prst.setString(1, str);
            prst.setString(2, str1);
            prst.setString(3, str2);
            ResultSet rs = prst.executeQuery();
            while (rs.next()) {
                Vector d = new Vector();
                d.add(rs.getString(1));
                d.add(rs.getString(2));
                d.add(rs.getString(3));
                d.add(rs.getString(4));
                d.add(rs.getString(5));
                d.add(rs.getString(6));
                d.add(rs.getString(7));
                d.add(rs.getString(8));
                d.add(rs.getString(9));
                d.add(rs.getString(10));
                model.addRow(d);
            }
            PreparedStatement prst5 = con.prepareStatement("select billstotal from billstotal where billcode=? and billtypecode=? and customercode=?");
            prst5.setString(1, str);
            prst5.setString(2, str1);
            prst5.setString(3, str3);
            ResultSet re5 = prst5.executeQuery();
            while (re5.next()) {
                jLabel9.setText(re5.getString(1));
            }
        } catch (SQLException ex) {
            Logger.getLogger(NewJFrame.class.getName()).log(Level.SEVERE, null, ex);
            JOptionPane.showMessageDialog(this, "Chua chon dieu kien tim kiem!", "ERROR", JOptionPane.ERROR_MESSAGE);
        }
    }//GEN-LAST:event_jTable2MouseClicked

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        // TODO add your handling code here:
        this.reset();
        int num = jTable1.getRowCount();
        for (int i = num - 1; i >= 0; i--) {
            model.removeRow(i);
        }
        t3.setEnabled(true);
        add.setEnabled(true);
    }//GEN-LAST:event_jButton1ActionPerformed

    private void t3KeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_t3KeyPressed
        // TODO add your handling code here:
        System.out.println("asdg");
    }//GEN-LAST:event_t3KeyPressed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        // TODO add your handling code here:
        Custommer.CustommerForBill cfb = new CustommerForBill();
        cfb.setVisible(true);
    }//GEN-LAST:event_jButton2ActionPerformed

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
        // TODO add your handling code here:
        Medicine.MedicineForBill mfb = new MedicineForBill();
        mfb.setVisible(true);
    }//GEN-LAST:event_jButton3ActionPerformed
    public void test(String text) {
        t3.setText(text);
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton add;
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.ButtonGroup buttonGroup2;
    private javax.swing.JButton check;
    private javax.swing.JButton del;
    private javax.swing.JButton edit;
    private javax.swing.JLabel id;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JCheckBox jCheckBox1;
    private javax.swing.JComboBox jComboBox1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JLabel jLabetotal;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JRadioButton jRadioButton1;
    private javax.swing.JRadioButton jRadioButton2;
    private javax.swing.JRadioButton jRadioButton3;
    private javax.swing.JRadioButton jRadioButton4;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTable jTable1;
    private javax.swing.JTable jTable2;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JTextField jTextField2;
    private javax.swing.JButton search;
    private javax.swing.JButton sort;
    private javax.swing.JTextField t1;
    private javax.swing.JTextField t3;
    private javax.swing.JTextField t4;
    private javax.swing.JTextField t5;
    private javax.swing.JTextField t6;
    private javax.swing.JTextField t7;
    // End of variables declaration//GEN-END:variables
}
